#include <WinTen.h>
#include <Windows.h>
#include <extend.h>

void WindowRaised( HDC, LPRECT );
void WindowBoxIn( HDC, LPRECT );

#define CLR_LIGHTGRAY           12632256          // RGB( 192, 192, 192 )

//----------------------------------------------------------------------------//

CLIPPER MSGPAINT()
{
   HWND  hWnd         = ( HWND ) _parnl( 1 );
   LPSTR cMsg         = _parc( 2 );
   LPSTR cMsgDef      = _parc( 3 );
   BOOL  bErase       = _parl( 4 );
   BOOL  bCenter      = _parl( 5 );
   int   nSize        = _parni( 6 );
   COLORREF nClrFore  = (PCOUNT() > 6) ? _parnl( 7 ) : 0;
   COLORREF nClrBack  = IF( PCOUNT() > 7, _parnl( 8 ), GetSysColor( COLOR_BTNFACE ) );
   HFONT hFont   = ( HFONT ) _parnl( 9 );
   BOOL bInset   = _parl( 10 );
   HFONT hOldFont;
   HDC   hDC     = GetDC( hWnd );
   RECT  rc;
   WORD  wLen, wRight;

   GetClientRect( hWnd, &rc );
   wRight = rc.right;

   SetTextColor( hDC, nClrFore );
   SetBkColor( hDC, nClrBack );

   rc.top    += 4;
   rc.left   += 4;
   rc.bottom -= 4;
   rc.right  -= 4;

   if( nSize )
      rc.right = nSize - 11;

   if( ! ( wLen = _parclen( 2 ) ) )
   {
      wLen = _parclen( 3 );
      cMsg = cMsgDef;
   }

   if( hFont )
      hOldFont = SelectObject( hDC, hFont );

   if( bCenter )
   {
      ExtTextOut( hDC, 8, 4, ETO_OPAQUE | ETO_CLIPPED, &rc, "", 0, 0 );
      DrawText( hDC, cMsg, wLen, &rc, IF( bCenter, DT_CENTER, DT_LEFT ) );
   }
   else
      ExtTextOut( hDC, 8, 4, ETO_OPAQUE | ETO_CLIPPED, &rc, cMsg, wLen, 0 );

   if( hFont )
      SelectObject( hDC, hOldFont );

   if( bErase )
   {
      rc.top    -= 4;
      rc.bottom += 3;
      rc.left   -= 4;
      rc.right  = wRight - 1;
      WindowRaised( hDC, &rc );

      if( bInset )
      {
         rc.top    += 3;
         rc.left   += 3;
         rc.right  = IF( nSize, nSize - 9, wRight - 4 );
         rc.bottom -= 3;
         WindowBoxIn( hDC, &rc );
      }
   }

   ReleaseDC( hWnd, hDC );
}

//----------------------------------------------------------------------------//
